{% extends '@YesknMain/base.html.twig' %}

{% block main %}
    <div class="home-content-main">
        {% if currentTab and currentTab.level == 2 %}
            <div class="tab-header">
               <div class="row">
                   <div class="col-md-2">
                       <div class="tab-avatar">
                           <img class=" img-rounded" src="{{ asset(currentTab.avatar) }}" alt="">
                       </div>
                   </div>
                   <div class="col-md-10">
                       <div class="tab-info">
                           <b>
                               <a href="{{ path('homepage') }}">{{ 'site_name'|trans }}</a>
                               <i class="fa  fa-angle-right"></i> <a data-pjax href="{{ path('post_list', {tab:currentTab.parent.alias}) }}">{{ currentTab.parent.name }}</a>
                               <i class="fa fa-angle-right"></i> {{ currentTab.name }}
                           </b>
                           <div style="padding: 10px 0">
                               {{ currentTab.description }}
                           </div>
                       </div>
                   </div>
               </div>
            </div>
        {% else %}
            <div class="tab-list">
                <a data-pjax class="{{ tab == 'all' ? 'current-tab':'' }}" href="{{ path('post_list', {tab: 'all'}) }}">{{ 'all'|trans }}</a>
                <a data-pjax class="{{ tab == 'hot' ? 'current-tab':'' }}"  href="{{ path('post_list', {tab: 'hot'}) }}">{{ 'hot'|trans }}</a>

                {% for tabItem in tabs %}
                    <a data-pjax class="{{ tab == tabItem.alias ? 'current-tab':'' }}"  href="{{ path('post_list', {tab: tabItem.alias}) }}">{{ tabItem.name|trans }}</a>
                {% endfor %}


                {% set routeName = app.request.attributes.get('_forwarded').get('_route') %}

                <div class="pull-right visible-lg panel-sort-btns">
                    <div class="btn-group btn-group-xs" role="group" aria-label="...">
                        <a data-pjax href="{{ path(routeName, {tab: tab, sortBy: 'pub'}) }}" class="btn btn-default {% if sortBy == 'pub' %}current{% endif %}">最新发布</a>
                        <a data-pjax href="{{ path(routeName, {tab: tab, sortBy: 'com'}) }}" class="btn btn-default {% if sortBy == 'com' %}current{% endif %}">最新评论</a>
                    </div>
                </div>
            </div>
        {% endif %}
        {% if posts is not empty %}
            {% for post in posts %}
                <article class="main" style="position: relative">
                    <div class="row">
                        <div class="col-md-1 post-avatar">
                            <img src="{{ asset(post.author.avatar) }}" class="img-rounded">
                        </div>
                        <div class="col-md-11 home-post-info">
                            <div class="item-title">
                                {% if post.isTop %}  <span class="warning-label x-small-font">{{ 'post_top'|trans }}</span> {% endif %}
                                <a data-pjax href="{{ path('post_show' , {'id' : post.id}) }}">{{ post.title }}</a>
                            </div>
                            <p class="post-meta">
                        <span><i class="fa fa-user"></i>
                            <a data-pjax href="{{ path('member_home', {username: post.author.username}) }}">{{ post.author.nickname }}</a></span>

                                <span class="category">
                                      <a data-pjax href="{{ path('post_list', {tab:post.tab.alias}) }}" class="badge">{{ post.tab.name|trans }}</a>
                                </span>

                                {% set postTime = sortBy == 'pub' ? post.createdAt : post.updatedAt %}
                                <span data-toggle="tooltip" title="{{ postTime|date }}">
                                    <i class="fa fa-clock-o"></i>
                                    {{ postTime|ago }}
                                </span>
                                <span><i class="fa fa-eye"></i> {{ post.views }}{{ 'click'|trans }}</span>
                                {% if post.comments.count %}
                                    <span><i class="fa fa-commenting-o"></i>
                                        <a data-pjax href="{{ path('post_show', {id:post.id}) }}#comments">{{ post.comments.count }}{{ 'comment'|trans }}</a>
                                    </span>
                                {% endif %}
                            </p>
                        </div>
                    </div>
                    {#{% if post.tags is not empty %}#}
                    {#<div style="position: relative;bottom:-10px">#}
                    {#<p>#}
                    {#<i class="fa  fa-tags item-tag"></i>#}
                    {#{% for tag in post.tags %}#}
                    {#<span class="item-tag"> {{ tag.name }} </span>#}
                    {#{% endfor %}#}
                    {#</p>#}
                    {#</div>#}
                    {#{% endif %}#}
                </article>
            {% endfor %}
            <ul class="pagination">
                {% set route = tab is not empty and tab != 'all' ? 'post_list' : 'post_list' %}
                {% if pageData.currentPage == 1 %}
                    <li class="disabled">
                        <a href="#">&laquo;</a>
                    </li>
                {% else %}
                    <li>
                        <a href="{{ path(route, {page:pageData['currentPage']-1,tab:tab}) }}" data-pjax>&laquo;</a>
                    </li>
                {% endif %}

                {% if pageData.currentPage > 3 %}
                    <li class="disabled">
                        <a href="#">...</a>
                    </li>
                {% endif %}

                {% for p in 1..pageData.allPage %}
                    {% if p < pageData.currentPage - 2 %}
                    {% endif %}

                    {% if p == pageData.currentPage %}
                        <li class="active"><a href="javascript:">{{ p }}</a></li>
                    {% elseif p >= pageData.currentPage - 2 and p != pageData.currentPage and p <= pageData.currentPage+2 %}
                        <li><a href="{{ path(route, {'page':p, tab:tab}) }}" data-pjax>{{ p }}</a></li>
                    {% endif %}


                    {% if p > pageData.currentPage+2 %}
                    {% endif %}
                {% endfor %}

                {% if pageData.allPage > pageData.currentPage+2 %}
                    <li class="disabled">
                        <a href="#">...</a>
                    </li>
                {% endif %}

                <li {% if pageData.currentPage == pageData.allPage %} class="disabled" {% endif %}>
                    <a href="{{ path(route, {page:pageData['currentPage']+1,tab:tab}) }}" data-pjax>&raquo;
                    </a>
                </li>
            </ul>
        {% else %}
        <div class="row">
            <div class="col-md-12">
                <div class="well" style="margin: 15px">{{ '暂时没有任何文档！' }}</div>
            </div>
        </div>
        {% endif %}
    </div>
{% endblock %}

